<script setup lang="ts">
  import { ref, defineProps, reactive, defineExpose } from "vue"
  import { createMessage } from '@/Public-UIlibrary/pb-message/method'
  import { getLevelEdit } from '@/api/Level'
  let props = defineProps({
    levelList: {
      type: Array,
      default: () => []
    }
  })
  let emits = defineEmits('onConfirmModal')
  let loading = ref(false)
  let appConfigForm = ref({
    tenantLevelId: "",
    tenantLevelRelationId: "",
    routeName: "",
    description: "",
    nodeType: 0
  })

  const appConfigFormRef = ref()
  let appConfigModalForm = ref(false)
  const onShow = (row) => {

    if (row) {
      let { parentrouteName, createTime, ...needFrom } = row
      appConfigForm.value = { ...needFrom }
    }
    appConfigModalForm.value = true
  }
  const onConfirmFn = () => {
    appConfigFormRef.value.validate((valid) => {
      if (valid) {
        getLevelEditApi()
      } else {

      }
    })
  }
  const getLevelEditApi = async () => {
    loading.value = true
    let res = await getLevelEdit({ ...appConfigForm.value })
    loading.value = false
    if (res.code == 2000) {
      createMessage({
        message: '编辑成功',
        type: 'success',
      })
      appConfigModalForm.value = false
      emits('onConfirmModal')
    }


  }
  defineExpose({ onShow })
</script>

<template>
  <pb-popup v-model="appConfigModalForm" :title="appConfigForm.tenantLevelId ? '编辑' : '新增'" Width="725"
    @confirmFn="onConfirmFn">

    <el-form :model="appConfigForm" ref="appConfigFormRef" label-width="auto" v-loading="loading" :inline="true">
      <el-form-item label="节点类型" prop="nodeType">
        <el-radio-group v-model="appConfigForm.nodeType" style="width: 240px;">
          <el-radio :value="0">目录</el-radio>
          <el-radio :value="1">菜单</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="路由名称" prop="routeName" :rules="[
        {
          required: true,
          message: '请输入路由名称',
          trigger: 'blur',
        }, ]" style="margin-right: 0;">
        <pb-input v-model=" appConfigForm.routeName" placeholder="请输入路由名称" />
      </el-form-item>
      <el-form-item label="上级节点" prop="routeName" :rules="[
                          {
                            required: true,
                            message: '请选择上级节点',
                            trigger: 'blur',
                          }, ]">
        <pb-select v-model="appConfigForm.tenantLevelId" placeholder="请选择上级节点" keys="tenantLevelId" label="routeName"
          :options="levelList" />
      </el-form-item>
      <el-form-item label="节点路由" prop="nodeIcon" style="margin-right: 0;">
        <pb-input v-model=" appConfigForm.nodeIcon" placeholder="请输入节点路由" />
      </el-form-item>

      <el-form-item label="文件路径" prop="routeName" v-if="appConfigForm.nodeType" :rules="[
              {
                required: true,
                message: '请选择文件路径',
                trigger: 'blur',
              }, ]">
        <pb-select v-model="appConfigForm.tenantLevelId" placeholder="请选择文件路径" keys="tenantLevelId" label="routeName"
          :options="levelList" />
      </el-form-item>
      <el-form-item label="按钮权限" prop="buttonPermissionsList" :rules="[
                          {
                            required: true,
                            message: '请选择按钮权限',
                            trigger: 'blur',
                          }, ]" v-if="appConfigForm.nodeType" style="margin-right: 0;">
        <pb-select v-model="appConfigForm.buttonPermissionsList" placeholder="请选择按钮权限" keys="tenantLevelId"
          label="routeName" :options="levelList" />
      </el-form-item>
      <el-form-item label="节点图标" prop="nodeIcon">
        <pb-input v-model=" appConfigForm.nodeIcon" placeholder="请输入节点图标" />
      </el-form-item>
      <el-form-item label="排序号" prop="buttonPermissionsList" style="margin-right: 0;">
        <pb-select v-model="appConfigForm.buttonPermissionsList" placeholder="" keys="tenantLevelId" label="routeName"
          :options="levelList" />
      </el-form-item>
    </el-form>
  </pb-popup>
</template>

<style lang="less" scoped>

</style>